package com.uzai.console.web.ks;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.console.annotation.SystemLogType;
import com.uzai.console.dto.device.DeviceQuery;
import com.uzai.console.dto.ks.ksorder.*;
import com.uzai.console.dto.user.UserQuery;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.mapper.DyTokenMapper;
import com.uzai.console.service.device.DeviceService;
import com.uzai.console.service.device.DeviceTypeService;
import com.uzai.console.service.ks.KsOrderService;
import com.uzai.console.service.order.OrderReStatusService;
import com.uzai.console.service.order.OrderSourceService;
import com.uzai.console.service.order.OrderStatusService;
import com.uzai.console.service.user.UserService;
import com.uzai.console.service.wechatprivate.DeviceWechatInfoService;
import com.uzai.console.vo.base.SelectKeyVo;
import com.uzai.console.vo.device.DeviceInfoVo;
import com.uzai.console.vo.ks.ksorder.KsOrderInfoVo;
import com.uzai.console.vo.ks.ksorder.KsOrderReportVo;
import com.uzai.console.vo.order.OrderReStatusVo;
import com.uzai.console.vo.order.OrderSourceVo;
import com.uzai.console.vo.order.OrderStatusVo;
import com.uzai.console.vo.user.UserInfoVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 快手订单
 * @author liuqi
 * @date 2021年08月16日 15:11
 */
@Api(value = "快手订单",tags = "快手|快手订单")
@ApiSort(10)
@RestController
public class KsOrderController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(KsOrderController.class);

    @Autowired
    private KsOrderService ksOrderService;
    @Autowired
    private OrderStatusService orderStatusService;
    @Autowired
    private OrderReStatusService orderReStatusService;
    @Autowired
    private OrderSourceService orderSourceService;
    @Autowired
    private DyTokenMapper dyTokenMapper;
    @Autowired
    private DeviceWechatInfoService deviceWechatInfoService;
    @Autowired
    private UserService userService;
    @Autowired
    private DeviceTypeService deviceTypeService;
    @Autowired
    private DeviceService deviceService;

    @ApiOperation(value = "查询快手订单列表", notes = "查询快手订单列表", response = KsOrderInfoVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/ksOrder/findKsOrderList")
    public Object findKsOrderList(@RequestBody KsOrderQuery ksOrderQuery){
        return ksOrderService.findKsOrderList(ksOrderQuery);
    }

    @ApiOperation(value = "查询快手订单详情", notes = "查询快手订单详情", response = KsOrderInfoVo.class)
    @ApiOperationSupport(order = 2)
    @PostMapping("/ksOrder/findKsOrderInfo")
    public Object findKsOrderInfo(@RequestBody KsOrderIdDto ksOrderIdDto){
        return ksOrderService.findKsOrderInfo(ksOrderIdDto);
    }

    @ApiOperation(value = "查询快手订单统计信息(总收入、买家总金额、总利润、未绑定用户利润、未收货返利金额）", notes = "查询快手订单统计信息(总收入、买家总金额、总利润、未绑定用户利润、未收货返利金额）", response = KsOrderReportVo.class)
    @ApiOperationSupport(order = 3)
    @PostMapping("/ksOrder/findKsOrderReport")
    public Object findKsOrderReport(@RequestBody KsOrderQuery ksOrderQuery){
        return ksOrderService.findKsOrderReport(ksOrderQuery);
    }

    @SystemLogType(model = SystemModelEnum.KsOrder, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "快手订单删除", notes = "快手订单删除")
    @ApiOperationSupport(order = 4)
    @PostMapping("/ksOrder/delKsOrder")
    public Object delKsOrder(@RequestBody KsOrderDelDto ksOrderDelDto){
        return ksOrderService.delKsOrder(ksOrderDelDto);
    }

    @SystemLogType(model = SystemModelEnum.KsOrder, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "快手订单确认收货", notes = "快手订单确认收货")
    @ApiOperationSupport(order = 5)
    @PostMapping("/ksOrder/confirmReceive")
    public Object confirmReceive(@RequestBody KsOrderIdDto ksOrderIdDto){
        return ksOrderService.confirmReceive(ksOrderIdDto);
    }

    @SystemLogType(model = SystemModelEnum.KsOrder, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "快手订单手动维权", notes = "快手订单手动维权")
    @ApiOperationSupport(order = 6)
    @PostMapping("/ksOrder/confirmRefund")
    public Object confirmRefund(@RequestBody KsOrderIdDto ksOrderIdDto){
        return ksOrderService.confirmRefund(ksOrderIdDto);
    }

    @SystemLogType(model = SystemModelEnum.KsOrder, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "快手订单订单冻结", notes = "快手订单订单冻结")
    @ApiOperationSupport(order = 7)
    @PostMapping("/ksOrder/confirmFrozen")
    public Object confirmFrozen(@RequestBody KsOrderIdDto ksOrderIdDto){
        return ksOrderService.confirmFrozen(ksOrderIdDto);
    }

    @SystemLogType(model = SystemModelEnum.KsOrder, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "快手订单订单解冻", notes = "快手订单订单解冻")
    @ApiOperationSupport(order = 8)
    @PostMapping("/ksOrder/confirmThaw")
    public Object confirmThaw(@RequestBody KsOrderIdDto ksOrderIdDto){
        return ksOrderService.confirmThaw(ksOrderIdDto);
    }

    @SystemLogType(model = SystemModelEnum.KsOrder, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "快手订单解绑用户", notes = "快手订单解绑用户")
    @ApiOperationSupport(order = 9)
    @PostMapping("/ksOrder/unbindUser")
    public Object unBindUser(@RequestBody KsOrderUnbindUserDto ksOrderUnbindUserDto){
        return ksOrderService.unbindUser(ksOrderUnbindUserDto);
    }

    @SystemLogType(model = SystemModelEnum.KsOrder, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "快手订单绑定用户", notes = "快手订单绑定用户")
    @ApiOperationSupport(order = 10)
    @PostMapping("/ksOrder/bindUser")
    public Object bindUser(@RequestBody KsOrderBindUserDto ksOrderBindUserDto){
        return ksOrderService.bindUser(ksOrderBindUserDto);
    }

    @SystemLogType(model = SystemModelEnum.KsOrder, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "快手订单修改解冻时间", notes = "快手订单修改解冻时间")
    @ApiOperationSupport(order = 11)
    @PostMapping("/ksOrder/updateThawTime")
    public Object updateThawTime(@RequestBody KsOrderThawTimeDto ksOrderThawTimeDto){
        return ksOrderService.updateThawTime(ksOrderThawTimeDto);
    }

    @SystemLogType(model = SystemModelEnum.KsOrder, type = OperationTypeEnum.DOWNLOAD)
    @ApiOperation(value = "快手订单手动下载快手订单", notes = "快手订单手动下载快手订单")
    @ApiOperationSupport(order = 13)
    @PostMapping("/ksOrder/downloadOrder")
    public Object downloadOrder(@RequestBody KsOrderDownLoadDto ksOrderDownLoadDto){
        ksOrderService.downloadOrder(ksOrderDownLoadDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.KsOrder, type = OperationTypeEnum.DOWNLOAD)
    @ApiOperation(value = "快手订单订单刷新", notes = "快手订单订单刷新")
    @ApiOperationSupport(order = 14)
    @PostMapping("/ksOrder/refreshOrder")
    public Object refreshOrder(@RequestBody KsOrderIdDto ksOrderIdDto){
        ksOrderService.refreshOrder(ksOrderIdDto);
        return true;
    }

    @ApiOperation(value = "快手订单查询快手订单状态列表", notes = "快手订单查询快手订单状态列表", response = OrderStatusVo.class)
    @ApiOperationSupport(order = 17)
    @PostMapping("/ksOrder/getOrderStatusList")
    public Object getOrderStatusList() {
        return orderStatusService.findKsOrderStatusList();
    }

    @ApiOperation(value = "快手订单查询快手订单返利状态列表", notes = "快手订单查询快手订单返利状态列表", response = OrderReStatusVo.class)
    @ApiOperationSupport(order = 18)
    @PostMapping("/ksOrder/getOrderReStatusList")
    public Object getOrderReStatusList() {
        return orderReStatusService.findKsOrderReStatusList();
    }

    @ApiOperation(value = "快手订单查询快手订单来源列表", notes = "快手订单查询快手订单来源列表", response = OrderSourceVo.class)
    @ApiOperationSupport(order = 19)
    @PostMapping("/ksOrder/getOrderSourceList")
    public Object getOrderSourceList() {
        return orderSourceService.findOrderSourceList();
    }

    @ApiOperation(value = "快手订单查询机器人下拉列表", notes = "快手订单查询机器人下拉列表", response = DeviceInfoVo.class)
    @ApiOperationSupport(order = 20)
    @PostMapping("/ksOrder/findDeviceWechatInfoSelectList")
    public Object findDeviceWechatInfoSelectList() {
        DeviceQuery deviceQuery = new DeviceQuery();
        deviceQuery.setMerId(getLoginInfo().getMerId());
        return deviceService.findDeviceList(deviceQuery);
    }

    @ApiOperation(value = "快手订单分页查询会员信息列表", notes = "快手订单分页查询会员信息列表", response = UserInfoVo.class)
    @ApiOperationSupport(order = 22)
    @PostMapping("/ksOrder/findUserPage")
    public Object findUserPage(@RequestBody UserQuery userQuery) {
        return userService.findUserPage(userQuery);
    }

    @ApiOperation(value = "快手订单查询设备类型下拉列表", notes = "快手订单查询设备类型下拉列表", response = SelectKeyVo.class)
    @ApiOperationSupport(order = 23)
    @PostMapping("/ksOrder/findDeiviceTypeListSelect")
    public Object findDeiviceTypeListSelect() {
        return deviceTypeService.findDeviceTypeListSelect();
    }

    @ApiOperation(value = "快手订单查询所有未绑定用户订单", notes = "快手订单查询所有未绑定用户订单", response = KsOrderInfoVo.class)
    @ApiOperationSupport(order = 24)
    @PostMapping("/ksOrder/findUnbindUserList")
    public Object findUnbindUserList(@RequestBody KsOrderUnbindDtoQuery ksOrderUnbindDtoQuery){
        return ksOrderService.findUnbindUserList(ksOrderUnbindDtoQuery);
    }

    @ApiOperation(value = "快手订单查询所有未绑定用户统计信息(总收入、买家总金额、总利润）", notes = "快手订单查询所有未绑定用户统计信息(总收入、买家总金额、总利润）", response = KsOrderReportVo.class)
    @ApiOperationSupport(order = 25)
    @PostMapping("/ksOrder/findUnbindUserReport")
    public Object findUnbindUserReport(@RequestBody KsOrderUnbindDtoQuery ksOrderUnbindDtoQuery){
        return ksOrderService.findUnbindUserReport(ksOrderUnbindDtoQuery);
    }

    @SystemLogType(model = SystemModelEnum.KsOrder, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "快手订单删除所有未绑定用户订单", notes = "快手订单删除所有未绑定用户订单", response = Boolean.class)
    @ApiOperationSupport(order = 26)
    @PostMapping("/ksOrder/deleteUnbindUserList")
    public Object deleteUnbindUserList(@RequestBody KsOrderDeleteUnbindDto ksOrderDeleteUnbindDto){
        return ksOrderService.deleteUnbindUserList(ksOrderDeleteUnbindDto);
    }

    @SystemLogType(model = SystemModelEnum.KsOrder, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "快手订单更新7天前未收货订单", notes = "快手订单更新7天前未收货订单", response = Boolean.class)
    @ApiOperationSupport(order = 27)
    @PostMapping("/ksOrder/updateKsOrderUnReceived")
    public Object updateKsOrderUnReceived(){
        ksOrderService.updateKsOrderUnReceivedList(getLoginInfo().getMerId());
        return true;
    }

    @SystemLogType(model = SystemModelEnum.KsOrder, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "追回返利", notes = "追回返利")
    @ApiOperationSupport(order = 28)
    @PostMapping("/ksOrder/rebateRefound")
    public Object rebateRefound(@RequestBody KsOrderIdDto ksOrderIdDto){
        return ksOrderService.rebateRefound(ksOrderIdDto);
    }
}
